import axios from './axios.ts'

// 注册接口
export function Register(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/register',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 登录接口
export function Login(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/login',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 更新个人信息
export function UpdateUserMess(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: `api/updateUserMess`,
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 获取指定用户信息
export function GetUserMess(phone:string):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: `api/getUserMess?phone=${phone}`
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 根据id获取指定用户信息
export function GetIdUserMess(user_id:number):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: `api/getIdUserMessage?user_id=${user_id}`
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 关注接口
export function FollowUser(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: `api/followUser`,
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}
